﻿using System;
using System.Linq;
using System.Diagnostics.Contracts;

namespace ReactiveCode.Util
{
    static partial class Disposable
    {
        class AnonymousDisposable : IDisposable
        {
            internal Action _dispose;
            public void Dispose()
            {
                if (_dispose != null)
                {
                    _dispose();
                    _dispose = null;
                }
            }
        }
        public static readonly IDisposable Empty = Create(delegate { });
        public static IDisposable Create(Action dispose)
        {
            Contract.Requires(dispose != null);
            return new AnonymousDisposable { _dispose = dispose };
        }
    }
}
